#import packages 
from erddapy import ERDDAP
import pandas as pd
import xarray as xr
import matplotlib.pyplot as plt
e = ERDDAP(
    server="https://data.cioospacific.ca/erddap",
    protocol="tabledap",
)
#set the boundary box
min_lat, max_lat = 49.28, 49.30
min_lon, max_lon = -126.62, -126.60
import folium

lon = (min_lon + max_lon) / 2
lat = (min_lat + max_lat) / 2

m = folium.Map(location=[lat, lon], tiles="OpenStreetMap", zoom_start=5)

folium.Polygon(
    [(min_lat, min_lon), (max_lat, min_lon), (max_lat, max_lon), (min_lat, max_lon)],
    fill=True,
).add_to(m)

m
Make this Notebook Trusted to load map: File -> Trust Notebook
df = pd.read_csv(e.get_search_url(response="csv"))
df["Dataset ID"]
0               allDatasets
1               BCSOP_daily
2             BCSOP_monthly
3      IYS_NISKIN_chl_phaeo
4              IYS_2020_CTD
5        IYS_2022_TINRO_CTD
6              IYS_2019_CTD
7           PRIMED_wavebuoy
8          IOS_CTD_Profiles
9         IOS_ADCP_Moorings
10         IOS_CTD_Moorings
11         IOS_CUR_Moorings
12         IOS_BOT_Profiles
13    IYS_2019_nutrients_O2
14             IYS_2019_POM
15           DFO_MEDS_BUOYS
16           ECCC_MSC_BUOYS
17       IOS_P26_Annualized
Name: Dataset ID, dtype: object
dataset_id = "IOS_CTD_Moorings"

e.dataset_id = dataset_id

#set search variables
e.variables = [
    "depth",
    "time",
    "latitude",
    "longitude",
    "sea_water_temperature",
    "sea_water_practical_salinity",
    "sea_water_pressure",
]

#set search criteria
e.constraints = {
    "latitude>=": 49.28,
    "latitude<=": 49.30,
    "longitude>=": -126.62,
    "longitude<=": -126.60,
}
df = e.to_pandas().dropna()
#df = e.to_pandas(index_col="time (UTC)").dropna()
df.head()
depth (m) time (UTC) latitude (degrees_north) longitude (degrees_east) sea_water_temperature (degC) sea_water_practical_salinity (PSS-78) sea_water_pressure (dbar)
891859 76.847060 2019-08-01T00:00:00Z 49.29 -126.60516 7.9147 33.2059 77.521
891860 76.741010 2019-08-01T00:15:00Z 49.29 -126.60516 7.9138 33.2488 77.414
891861 76.635950 2019-08-01T00:30:00Z 49.29 -126.60516 7.9144 33.2564 77.308
891862 76.547745 2019-08-01T00:45:00Z 49.29 -126.60516 7.9842 33.1616 77.219
891863 76.495210 2019-08-01T01:00:00Z 49.29 -126.60516 7.8992 33.2524 77.166
df.shape
(236387, 7)
lat_moorings = df["latitude (degrees_north)"]
lon_moorings = df["longitude (degrees_east)"]

for i in range (0, len(df)):
    folium.Marker([df.iloc[i]["latitude (degrees_north)"], df.iloc[i]["longitude (degrees_east)"]]).add_to(m)

m
#m_moorings = folium.Map(location=[lat_moorings, lon_moorings], tiles="OpenStreetMap", zoom_start=5)
Make this Notebook Trusted to load map: File -> Trust Notebook
len(lon_moorings)
len(df)